<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>生态瞬时测试</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="../css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="../css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="../css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="../css/animate.css" rel="stylesheet">
    <link href="../css/style.css?v=4.1.0" rel="stylesheet">
    <link rel="stylesheet" href="../css/paging.css">

</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">

    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <!--<h5>实验管理</h5>-->
                </div>
                <div class="ibox-content">
                    <div class="row">
                        <div class="col-sm-5 m-b-xs">
                        </div>
                        <div class="col-sm-4 m-b-xs">
                        </div>
                        <div class="col-sm-3">
                            <a href="election.html" class="btn btn-sm btn-primary">添加题目</a>
                        </div>
                    </div>
                    <div class="table-responsive">
                        <table class="table table-bordered table-striped">
                            <thead>
                            <tr>
                                <th>题目编号</th>
                                <th>题目标题</th>
                                <th>题目类型</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody id="exam-box">
                            <!--表格加载内容显示-->
                            </tbody>
                        </table>
                    </div>
                    <div class="paging">
                        <div id="paging" class="page_div"></div>
                    </div>
                </div>

            </div>

        </div>

    </div>
</div>

<!-- 全局js -->
<script src="../js/jquery.min.js?v=2.1.4"></script>
<script src="../js/bootstrap.min.js?v=3.3.6"></script>
<script src="../js/paging.js"></script>
<!-- iCheck -->
<script src="../js/plugins/iCheck/icheck.min.js"></script>
<script>
    $(document).ready(function () {
        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green',
        });
    });
</script>
<script>
    $(document).ready(function () {
        var examName = sessionStorage.getItem("examName");
        $(".ibox-title").html(`<h5>${examName} 试题管理</h5>`);
        var token = sessionStorage.getItem("token");
        var examId = sessionStorage.getItem("examId");
        $.ajax({
            type:"GET",
            url:"http://123.206.18.189:8080/question/paper/"+examId,
            headers:{
                authToken:token
            },
            dataType:"json",
            success:function (res) {
                var html = "";
                for(var i=0;i<res.length;i++){
                    var electionType = res[i].type =="single"?"单选":"多选";
                    html += ` <tr>
                                    <td>${res[i].id}</td>
                                    <td>${res[i].title}</td>
                                    <td>${electionType}</td>
                                    <td>
                                        <!--<i class="fa fa-edit edit" title="修改" style="margin-right: 20px;"></i>-->
                                        <i class="fa fa-edit edit" title="查看试题" style="margin-right: 20px;"></i>
                                        <i class="fa fa-trash-o del" title="删除试题" style="margin-right: 20px;"></i>
                                    </td>
                                </tr>`
                }
                $("#exam-box").html(html);
            }
        })

        //删除试题
        $("#exam-box").on("click",".del",function () {
            var questionId = $(this).parent().parent().children().eq(0).text();
            var r = confirm("是否确认删除该试题？");
            if(r){
                $.ajax({
                    type:"DELETE",
                    url:"http://123.206.18.189:8080/question/"+questionId,
                    headers:{
                        authToken:token
                    },
                    success:function(){
                        //console.log(1);
                    },
                    complete:function (xhr) {
                        alert("删除成功！");
                        window.location.reload()
                    }
                })
            }
        })
        //修改试题
        $("#exam-box").on("click",".edit",function () {
            var questionId = $(this).parent().parent().children().eq(0).text();
            sessionStorage.setItem("questionId",questionId);
            window.location.href = "electionChange.html";
        })
    })
</script>

</body>

</html>
